package com.liu.webstore.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author LiuYumei
 * @Date 2022/7/23 10:11
 */
public class CookieUtil {
    public static String getValue(HttpServletRequest request, String name) throws Exception {
        if (request == null || name == null) {
            throw new IllegalAccessException("参数为空！");
        }
        Cookie[] cookies = request.getCookies();
        if (null != cookies && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                if (name.equals(cookie.getName())) {
                    return cookie.getValue();
                }
            }
        }
    return null;
    }
}
